package cn.structure.edp;

import cn.structure.ClassEntity;

import java.util.Objects;

public class Inheritance extends EdpEntity {
    private ClassEntity subClass;
    private ClassEntity superClass;

    public Inheritance(ClassEntity subClass, ClassEntity superClass) {
        super();
        this.subClass = subClass;
        this.superClass = superClass;
    }

    public enum Role {
        subClass, superClass
    }

    public ClassEntity getSubClass() {
        return subClass;
    }

    public void setSubClass(ClassEntity subClass) {
        this.subClass = subClass;
    }

    public ClassEntity getSuperClass() {
        return superClass;
    }

    public void setSuperClass(ClassEntity superClass) {
        this.superClass = superClass;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Inheritance{\n\t");
        sb.append(super.toString());
        sb.append("\n\t\"subClass\":")
                .append(subClass);
        sb.append(",\n\t\"superClass\":")
                .append(superClass);
        sb.append("\n}");
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        Inheritance that = (Inheritance) o;
        return Objects.equals(subClass, that.subClass) &&
                Objects.equals(superClass, that.superClass);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), subClass, superClass);
    }
}
